package com.example.mqcomsumer.service;

import com.alibaba.fastjson.JSONArray;
import com.example.mqcomsumer.model.User;
import org.apache.tomcat.util.json.JSONParser;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;
import java.util.Map;


@Component
public class MQListener {


    @RabbitHandler
    @RabbitListener(queues = "fanout_queue_email")
    public void comsumer(Message message) throws UnsupportedEncodingException {

        Jackson2JsonMessageConverter jackson2JsonMessageConverter = new Jackson2JsonMessageConverter();

       User user= (User) jackson2JsonMessageConverter.fromMessage(message);

        System.out.println(user.getUsername());
    }
}
